package net.dodoman.thread;

public class TwoTest {

	Thread th1 = new Thread(new Th1());// 定义线程1
	Thread th2 = new Thread(new Th2());// 定义线程2

	public TwoTest() {
		this.th1.start();
		this.th2.start();
	}

	public static void main(String[] args) {
		new TwoTest();
	}

	// 线程1
	class Th1 implements Runnable {

		public void run() {
			while (true) {
				System.out.println("我是线程1");
				try {
					th1.sleep(1000);// 一秒后在次运行
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}
	}

	// 线程2
	class Th2 implements Runnable {
		public void run() {
			while (true) {
				System.out.println("我是线程2");
				try {
					th2.sleep(3000);// 3秒后再此运行
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}
	}
}